﻿#include "PlatformProperty.h"

MAPPING_VALUE(sdb::AvailabilitySts, PropertyStatus, PropertyStatus::NotAvailable)
    MAPPING_ITEM(sdb::AvailabilitySts::Active, PropertyStatus::Active)
    MAPPING_ITEM(sdb::AvailabilitySts::NotActive, PropertyStatus::NotActive)
    MAPPING_ITEM(sdb::AvailabilitySts::Error, PropertyStatus::Error)
    MAPPING_ITEM(sdb::AvailabilitySts::NotAvailable, PropertyStatus::NotAvailable)
MAPPING_END

SYSTEM_READ_WRITE_PROPERTY(HVAC_AUTO_ON, bool) {
    builder.area(VehicleAreaSeat::ROW_1_LEFT | VehicleAreaSeat::ROW_1_RIGHT)
            .initValue([]() { return false; })
            .withStatusBySignals([]([[maybe_unused]] const PropertyStatus &lastStatus) {
                sdb::AvailabilitySts availabilitySts = sdb::AvailabilitySts(SIGNAL.getPA_CL_Auto().availability);
                PropertyStatus status = mappingValue(availabilitySts, PropertyStatus::NotAvailable);
                VHALOG.d("HVAC_AUTO_ON zone_all status changed to: %d ", status);
                return status;
            }, PASignal::PA_CL_Auto)
            .withValueBySignals([]([[maybe_unused]] const bool &last) {
                // RX信号变化时，重新计算功能值
                int data = SIGNAL.getPA_CL_Auto().data;
                VHALOG.d("HVAC_AUTO_ON zone_all value changed to: %d ", data);
                return data == 1 ? true : false;
            }, PASignal::PA_CL_Auto)
            .onSetProperty([](const bool value) {
                VHALOG.d("halOnSetProperty HVAC_AUTO_ON : %d", value);
                SIGNAL.setCB_CL_Auto(value ? (sdb::LongPresBtn::On) : (sdb::LongPresBtn::Off));
            })
            .area(VehicleAreaSeat::ROW_1_RIGHT)
            .initValue([]() { return false; })
            .withStatusBySignals([]([[maybe_unused]] const PropertyStatus &lastStatus) {
                sdb::AvailabilitySts availabilitySts = sdb::AvailabilitySts(SIGNAL.getPA_CL_AutoRi().availability);
                PropertyStatus status = mappingValue(availabilitySts, PropertyStatus::NotAvailable);
                VHALOG.d("HVAC_AUTO_ON row_1_right status changed to: %d ", status);
                return status;
            }, PASignal::PA_CL_AutoRi)
            .withValueBySignals([]([[maybe_unused]] const bool &last) {
                // RX信号变化时，重新计算功能值
                int data = SIGNAL.getPA_CL_AutoRi().data;
                VHALOG.d("HVAC_AUTO_ON row_1_right value changed to: %d ", data);
                return data == 1 ? true : false;
            }, PASignal::PA_CL_AutoRi)
            .onSetProperty([](const bool value) {
                VHALOG.d("halOnSetProperty HVAC_AUTO_ON : %d", value);
                SIGNAL.setCB_CL_AutoRi(value ? (sdb::LongPresBtn::On) : (sdb::LongPresBtn::Off));
            })
            .area(VehicleAreaSeat::ROW_2_RIGHT | VehicleAreaSeat::ROW_2_LEFT |
                  VehicleAreaSeat::ROW_2_CENTER)
            .initValue([]() { return false; })
            .withStatusBySignals([]([[maybe_unused]] const PropertyStatus &lastStatus) {
                sdb::AvailabilitySts availabilitySts = sdb::AvailabilitySts(SIGNAL.getPA_CL_SecAutoSw().availability);
                PropertyStatus status = mappingValue(availabilitySts, PropertyStatus::NotAvailable);
                VHALOG.d("HVAC_AUTO_ON row_2 status changed to: %d ", status);
                return status;
            }, PASignal::PA_CL_SecAutoSw)
            .withValueBySignals([]([[maybe_unused]] const bool &last) {
                // RX信号变化时，重新计算功能值
                int data = SIGNAL.getPA_CL_SecAutoSw().data;
                VHALOG.d("HVAC_AUTO_ON row_2 value changed to: %d ", data);
                return data == 1 ? true : false;
            }, PASignal::PA_CL_SecAutoSw)
            .onSetProperty([](const bool value) {
                VHALOG.d("halOnSetProperty HVAC_AUTO_ON  row2 : %d", value);
                SIGNAL.setCB_CL_SecAutoSw(value ? (sdb::OnOff1::On) : (sdb::OnOff1::Off));
            })
            .area(VehicleAreaSeat::ROW_2_RIGHT)
            .initValue([]() { return false; })
            .withStatusBySignals([]([[maybe_unused]] const PropertyStatus &lastStatus) {
                sdb::AvailabilitySts availabilitySts = sdb::AvailabilitySts(SIGNAL.getPA_CL_SecAutoSwRi().availability);
                PropertyStatus status = mappingValue(availabilitySts, PropertyStatus::NotAvailable);
                VHALOG.d("HVAC_AUTO_ON row_2_right status changed to: %d ", status);
                return status;
            }, PASignal::PA_CL_SecAutoSwRi)
            .withValueBySignals([]([[maybe_unused]] const bool &last) {
                // RX信号变化时，重新计算功能值
                int data = SIGNAL.getPA_CL_SecAutoSwRi().data;
                VHALOG.d("HVAC_AUTO_ON row_2_right value changed to: %d ", data);
                return data == 1 ? true : false;
            }, PASignal::PA_CL_SecAutoSwRi)
            .onSetProperty([](const bool value) {
                VHALOG.d("SOME ONE SET HVAC_AUTO_ON Row2right : %d", value);
                SIGNAL.setCB_CL_SecAutoSwRi(value ? (sdb::OnOff1::On) : (sdb::OnOff1::Off));
            });
}
